package model;

import java.util.Vector;

import javax.microedition.lcdui.Graphics;

import main.GameCanvas;
import screen.PaintPopup;
import font.BitmapFont;

public class ItemInfo extends MyObj {
	public byte m_bItemType;
	public short m_sImgID;
	public int m_sExperience;
	public int m_iVersion;
	public int[] m_iMoney = new int[2];
	public short m_sLevelRequired = 0;
		
	protected Vector m_vtDescription = new Vector();
	public int m_iWidthInfo;
	public int m_iHeightInfo;
	
	public Part m_imgPart;
	public String m_strFrameImg;
	
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
	}

	public void paintIcon(Graphics g, int x, int y) {
		// TODO Auto-generated method stub
		int tmpX = Math.abs(m_imgPart.m_iW - 32);
		int tmpY = Math.abs(m_imgPart.m_iH - 32);
		
		m_imgPart.paintPart(g, 0, x + tmpX / 2, y + tmpY / 2, 0);
	}
	
	public void paintInRow(Graphics g, int x, int y, int width, int height, boolean isFocus) {
		// TODO Auto-generated method stub
	}
	//paint the popup description in shop
	public void paintInfo(Graphics g, int x, int y) {
		int delta = y + m_iHeightInfo - (GameCanvas.h - 20);
		//select the best position for popup
		if(delta > 0){
			int delta1 = y - m_iHeightInfo - 32;
			if(delta1 < 0){
				if(Math.abs(delta) > Math.abs(delta1)){
					y = delta1;
				}
				else
					y -= 11;	
			}
			else
				y = delta1;
		}
		
		if(x + m_iWidthInfo > GameCanvas.w){
			x -= (x + m_iWidthInfo - GameCanvas.w);
		}
				
		//paint bounding
		PaintPopup.paintRoundRect(g, x, y, m_iWidthInfo, m_iHeightInfo, 0xffe783);
		
		//paint item's name
		y += 5;
		String str = (String)m_vtDescription.elementAt(0);
		BitmapFont.drawBoldFont(g, str, x + m_iWidthInfo/2, y, 0x3a001e, Graphics.TOP|Graphics.HCENTER);
		
		//paint details        
		int a = m_vtDescription.size();
		for(int i = 1; i < a; i++){
			y += 15;
			str = (String)m_vtDescription.elementAt(i);
			BitmapFont.drawNormalFont(g, str, x+10, y, 0x3a001e, Graphics.LEFT);
		}
	}
	
	public void initDescription(){
		m_vtDescription.removeAllElements();
	}
	
	public MyObj clone() {
		// TODO Auto-generated method stub
		ItemInfo item = new ItemInfo();
		
		item.m_bItemType = this.m_bItemType;
		item.m_iId = this.m_iId;
		item.m_iMoney[0] = this.m_iMoney[0];
		item.m_iMoney[1] = this.m_iMoney[1];
		item.m_iVersion = this.m_iVersion;
		item.m_sExperience = this.m_sExperience;
		item.m_sImgID = this.m_sImgID;
		item.m_strName = this.m_strName;
		
		return item;
	}


	public void importFrameImg(String frameStr) {
		// TODO Auto-generated method stub
		m_strFrameImg = frameStr;
		
		String[] arr = BitmapFont.splitString(frameStr, ",");
        
		m_imgPart.m_iImgId = Integer.parseInt(arr[0]);
		m_imgPart.m_iX = Integer.parseInt(arr[1]);
		m_imgPart.m_iY = Integer.parseInt(arr[2]);
		m_imgPart.m_iW = Integer.parseInt(arr[3]);
		m_imgPart.m_iH = Integer.parseInt(arr[4]);
	}
}
